#include "linechart.h"

LineChart::LineChart()
{
    Line1=new QLineSeries();//曲线1
    chart=new QChart();
    chart->addSeries(Line1);
    chartview=new QChartView(chart);
    chartview->setRenderHint(QPainter::Antialiasing);
    chartview->setRubberBand(QChartView::RectangleRubberBand);
    axisX=new QValueAxis();
    axisY=new QValueAxis();
}

void LineChart::SetAxis(int Xmin, int Xmax, int Ymin, int Ymax)
{
    axisX->setRange(Xmin,Xmax);
    axisX->setLabelFormat("%.1f");//显示的数据保留一位小数
    axisX->setTickCount(5);//设置X轴的刻度数
    axisY->setRange(Ymin,Ymax);
    axisY->setLabelFormat("%.1f");//显示的数据保留一位小数
    axisY->setTickCount(4);//设置X轴的刻度数
    chart->setAxisX(axisX,Line1);
    chart->setAxisY(axisY,Line1);
    Line1->setUseOpenGL(true);

    QPen pen1(Qt::red,5,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin);
    Line1->setPen(pen1);
}

void LineChart::SetChartTitleText(QString title)
{
    chart->setTitle(title);
}

void LineChart::SetChartLegend()
{
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->show();
}

void LineChart::ConfigLine1Series(QString name)
{
    Line1->setName(name);
    //chart->addSeries(Line1);
}

void  LineChart::SetAxisXmax(float AxisXMax)
{
    axisX->setMax(AxisXMax);
}

void LineChart::ResetAxisY(float OriginalAxisYmin, float OriginalAxisYmax)
{
    axisY->setMax(OriginalAxisYmax);
    axisY->setMin(OriginalAxisYmin);
}

void LineChart::SetAxisYMin(float AxisYMin)
{
    axisY->setMin(AxisYMin);
}

void LineChart::SetAxisYMax(float AxisYMax)
{
    axisY->setMax(AxisYMax);
}

void LineChart::ClearChart()
{

    Line1->clear();
    chart->removeSeries(Line1);
}

void LineChart::ResetZoomChart(float OriginalAxisXMax)
{
    axisX->setMax(OriginalAxisXMax);
}

void LineChart::ZoomOutChart(float OriginalAxisX, float Multiple)
{
    axisX->setMax(OriginalAxisX*Multiple);
}

void LineChart::ZoomInChart(float OriginalAxisX, float Multiple)
{
    axisX->setMax(OriginalAxisX*Multiple);
}

void LineChart::DrawLine1(QPointF point)
{
    Line1->append(point);
}
